package 链表;

public class _删除链表的倒数第N个节点 {
	public ListNode removeNthFromEnd(ListNode head, int n) {
		ListNode tmp = new ListNode(0);
		tmp.next = head;
		ListNode fast = tmp;
		ListNode slow = tmp;
		for (int i = 0; i < n+1; i++) {
			fast = fast.next;
		}
		while (fast != null) {
			slow = slow.next;
			fast = fast.next;
		}
		slow.next = slow.next.next;
		return tmp.next;

//		ListNode fast = head;
//		ListNode slow = head;
//		while (fast.next != null) {
//			fast = fast.next;
//			if (n == 0) {
//				slow = slow.next;
//			} else {
//				n--;
//			}
//		}
//		return head;

	}
}
